{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "#编写程序，将等比数列的前99行 1/2+1/4+1/8+1/16+...+1/2^N 的算式及和写到一个文本文件中。\n",
    "with open('homework0.txt','w',encoding='utf-8') as f:\n",
    "    s = 0\n",
    "    for i in range(1,100):\n",
    "        s += (1/2)**i\n",
    "        f.write(str(s) + '\\n')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2.0\n",
      "1.5\n",
      "1.6666666666666667\n",
      "1.6\n",
      "1.625\n",
      "1.6153846153846154\n",
      "1.619047619047619\n",
      "1.6176470588235294\n",
      "1.6181818181818182\n",
      "362.85395148962107\n"
     ]
    }
   ],
   "source": [
    "#将初始半径为1的 斐波那契弧线（螺旋线） 的前50步的长度和，以及分步与上一步的长度比打印出来。\n",
    "def fibo(n):\n",
    "    if n == 0:\n",
    "        return 1\n",
    "    elif n == 1:\n",
    "        return 1\n",
    "    else:\n",
    "        return fibo(n-1)+fibo(n-2)\n",
    "import math\n",
    "s = 0\n",
    "for i in range(1,51):\n",
    "    s += math.pi*fibo(i)/2\n",
    "    if i >= 2:\n",
    "        print(fibo(i)/fibo(i-1))\n",
    "print(s)"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "1baa965d5efe3ac65b79dfc60c0d706280b1da80fedb7760faf2759126c4f253"
  },
  "kernelspec": {
   "display_name": "Python 3.8.10 64-bit",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
